<?php defined('IN_NWIDC') or exit('Access Invalid!');?>
<style>
.ncc-table-style tbody tr.item_disabled td {
	background: none repeat scroll 0 0 #F9F9F9;
	height: 30px;
	padding: 10px 0;
	text-align: center;
}
</style>
<?php
    $m = Model('setting');
    $config = $m->getListSetting();
    //加载设置模板样式下购物车样式表
    @include dirname(BASE_PATH) . '/shop/templates/' . $config['template_name'] . '/fix_cart.php';
?>

<div class="ncc-main" >
  <div class="ncc-title">
    <h3><?php echo $lang['cart_index_ensure_order'];?></h3>
    <h5>查看购物车商品清单，增加减少商品数量，并勾选想要的商品进入下一步操作。</h5>
  </div>

  <form action="<?php echo urlShop('buy','buy_step1');?>" method="POST" id="form_buy" name="form_buy">
    <input type="hidden" value="1" name="ifcart">
    <table class="ncc-table-style" nc_type="table_cart">
      <thead>
        <tr>
          <th class="w50"><label>
              <input type="checkbox" checked value="1" id="selectAll">
              全选</label></th>
          <th></th>
          <th><?php echo $lang['cart_index_store_goods'];?></th>
          <th class="w120"><?php echo $lang['cart_index_price'].'('.$lang['currency_zh'].')';?></th>
          <?php
          if(is_proxy()){
        ?>
        <th class='w120'>代理价格</th>
        <?php
          }
        ?>
          <?php
            if($config['open_tax'] == 1){

          ?>
          <th class='w120'>综合税(每件)</th>

          <?php
            }
          ?>
          <th class="w120"><?php echo $lang['cart_index_amount'];?></th>
          <th class="w120"><?php echo $lang['cart_index_sum'].'('.$lang['currency_zh'].')';?></th>
          <th class="w80"><?php echo $lang['cart_index_handle'];?></th>
        </tr>
      </thead>
      <?php foreach($output['store_cart_list'] as $store_id => $cart_list) {?>
      <tbody>
        <tr>
          <th colspan="20">
            <strong>店铺：<a href="<?php echo urlShop('show_store','index',array('store_id'=>$store_id), $output['store_list'][$store_id]['store_domain']);?>"><?php echo $cart_list[0]['store_name']; ?></a></strong> <span member_id="<?php echo $output['store_list'][$store_id]['member_id'];?>"></span>
            <?php if (!empty($output['free_freight_list'][$store_id])) {?>
            <div class="store-sale"><em><i class="icon-gift"></i>免运费</em><?php echo $output['free_freight_list'][$store_id];?>&emsp;</div>
            <?php } ?>
          </th>
        </tr>

        <!-- S one store list -->
        <?php foreach($cart_list as $cart_info) {?>
        <tr id="cart_item_<?php echo $cart_info['cart_id'];?>" nc_group="<?php echo $cart_info['cart_id'];?>" class="shop-list <?php echo $cart_info['state'] ? '' : 'item_disabled';?>">
          <td>
          <input type='hidden' nc-type='goods_tax_total' value='<?php echo $cart_info[goods_tax_total]?>' />

          <input type="checkbox" <?php echo $cart_info['state'] ? 'checked' : 'disabled';?> nc_type="eachGoodsCheckBox" value="<?php echo $cart_info['cart_id'].'|'.$cart_info['goods_num'];?>" id="cart_id<?php echo $cart_info['cart_id'];?>" name="cart_id[]"></td>
          <?php if ($cart_info['bl_id'] == '0') {?>
          <td class="w60"><a href="<?php echo urlShop('goods','index',array('goods_id'=>$cart_info['goods_id']));?>" target="_blank" class="ncc-goods-thumb"><img src="<?php echo thumb($cart_info,60);?>" alt="<?php echo $cart_info['goods_name']; ?>" /></a></td>
          <?php } ?>
          <td class="tl" <?php if ($cart_info['bl_id'] != '0') {?>colspan="2"<?php }?>><dl class="ncc-goods-info">
              <dt><a href="<?php echo urlShop('goods','index',array('goods_id'=>$cart_info['goods_id']));?>" target="_blank"><?php echo $cart_info['goods_name']; ?></a></dt>
              <?php
              $xianshi_state = $xianshi_state == true ? true:false;
                if (!empty($cart_info['xianshi_info'])) {
                $xianshi_state = true;
              ?>
              <dd> <span class="xianshi">满<strong><?php echo $cart_info['xianshi_info']['lower_limit'];?></strong>件，单价直降<em>￥<?php echo $cart_info['xianshi_info']['down_price']; ?></em></span> </dd>
              <?php }?>
              <?php if ($cart_info['ifgroupbuy']) {?>
              <dd> <span class="groupbuy">抢购<?php if ($cart_info['upper_limit']) {?>，最多限购<strong><?php echo $cart_info['upper_limit']; ?></strong>件<?php } ?></span></dd>
              <?php }?>
              <?php if ($cart_info['bl_id'] != '0') {?>
              <dd><span class="buldling">优惠套装，单套直降<em>￥<?php echo $cart_info['down_price']; ?></em></span></dd>
              <?php }?>

              <!-- S gift list -->
              <?php if (!empty($cart_info['gift_list'])) {?>
              <dd><span class="ncc-goods-gift">赠</span>
                <ul class="ncc-goods-gift-list">
                  <?php foreach ($cart_info['gift_list'] as $goods_info) { ?>
                  <li nc_group="<?php echo $cart_info['cart_id'];?>"><a href="<?php echo urlShop('goods','index',array('goods_id'=>$goods_info['gift_goodsid']));?>" target="_blank" class="thumb" title="赠品：<?php echo $goods_info['gift_goodsname']; ?> * <?php echo $goods_info['gift_amount'] * $cart_info['goods_num']; ?>"><img src="<?php echo cthumb($goods_info['gift_goodsimage'],60,$store_id);?>" alt="<?php echo $goods_info['gift_goodsname']; ?>" /></a>
                    <?php } ?>
                  </li>
                </ul>
              </dd>
              <?php  } ?>
              <!-- E gift list -->
            </dl></td>
          <td class="w120"><em id="item<?php echo $cart_info['cart_id']; ?>_price">
          <?php
               echo $cart_info['goods_price'];
          ?>
          </em></td>
          <?php
              if(is_proxy()){
          ?>
          <td>
            <em>
              <?php echo $cart_info['goods_proxy']?>
            </em>
          </td>
          <?php
              }
          ?>
          <?php if($config['open_tax'] == 1){?>
          <td class='w120 tax'>
              <em>
              <?php
                if(isset($cart_info['tax']) && $cart_info['tax'] > 0){
                  echo $cart_info['tax'];
                }
                else{
                  echo '0';
                }
              ?>
              </em>
          </td>
          <?php }?>
          <?php if ($cart_info['state']) {?>
          <td class="w120 ws0"><a href="JavaScript:void(0);" onclick="decrease_quantity(<?php echo $cart_info['cart_id']; ?>);" title="<?php echo $lang['cart_index_reduse'];?>" class="add-substract-key tip">-</a>
            <input id="input_item_<?php echo $cart_info['cart_id']; ?>" value="<?php echo $cart_info['goods_num']; ?>" orig="<?php echo $cart_info['goods_num']; ?>" changed="<?php echo $cart_info['goods_num']; ?>" onkeyup="change_quantity(<?php echo $cart_info['cart_id']; ?>, this);" type="text" class="text w20"/>
            <a href="JavaScript:void(0);" onclick="add_quantity(<?php echo $cart_info['cart_id']; ?>);" title="<?php echo $lang['cart_index_increase'];?>" class="add-substract-key tip" >+</a></td>
          <?php } else {?>
          <td class="w120">无效
            <input type="hidden" value="<?php echo $cart_info['cart_id']; ?>" name="invalid_cart[]"></td>
          <?php }?>

          <td class="w120"><?php if ($cart_info['state']) {?>
            <em id="item<?php echo $cart_info['cart_id']; ?>_subtotal" nc_type="eachGoodsTotal"><?php echo $cart_info['goods_total'] - $cart_info['goods_tax_total']; ?></em>
            <?php }?></td>
          <td class="w80"><?php if ($cart_info['bl_id'] == '0') {?>
            <a href="javascript:void(0)" onclick="collect_goods('<?php echo $cart_info['goods_id']; ?>');"><?php echo $lang['cart_index_favorite'];?></a><br/>
            <?php } ?>
            <a href="javascript:void(0)" onclick="drop_cart_item(<?php echo $cart_info['cart_id']; ?>);"><?php echo $lang['cart_index_del'];?></a></td>
        </tr>

        <!-- S bundling goods list -->
        <?php if (is_array($cart_info['bl_goods_list'])) {?>
        <?php foreach ($cart_info['bl_goods_list'] as $goods_info) { ?>
        <tr class="shop-list <?php echo $cart_info['state'] ? '' : 'item_disabled';?>" nc_group="<?php echo $cart_info['cart_id'];?>">
          <td></td>
          <td class="w60"><a href="<?php echo urlShop('goods','index',array('goods_id'=>$goods_info['goods_id']));?>" target="_blank" class="ncc-goods-thumb"><img src="<?php echo cthumb($goods_info['goods_image'],60,$store_id);?>" alt="<?php echo $goods_info['goods_name']; ?>" /></a></td>
          <td class="tl"><dl class="ncc-goods-info">
              <dt><a href="<?php echo urlShop('goods','index',array('goods_id'=>$goods_info['goods_id']));?>" target="_blank"><?php echo $goods_info['goods_name']; ?></a> </dt>
            </dl></td>
          <td><em><?php echo $goods_info['bl_goods_price'];?></em></td>
          <td><?php echo $cart_info['state'] ? '' : '无效';?></td>
          <td></td>
          <td><a href="javascript:void(0)" onclick="collect_goods('<?php echo $goods_info['goods_id']; ?>');"><?php echo $lang['cart_index_favorite'];?></a><br/></td>
        </tr>
        <?php } ?>
        <?php  } ?>
        <!-- E bundling goods list -->

        <?php } ?>
        <!-- E one store list -->

        <!-- S mansong list -->
        <?php if (!empty($output['mansong_rule_list'][$store_id]) && is_array($output['mansong_rule_list'][$store_id]) && $xianshi_state !== true ) {?>
        <tr nc_group="<?php echo $cart_info['cart_id'];?>">
          <td></td>
          <td class="tl" colspan="10"><div class="store-sale"><em> <i class="icon-gift"></i> 满即送 </em><?php echo implode('<br/>', $output['mansong_rule_list'][$store_id]);?></div></td>
        </tr>
        <?php }?>
        <!-- E mansong list -->

        <tr>
          <td class="tr" colspan="20"><div class="ncc-store-account">
              <dl>
                <dt>店铺合计：</dt>
                <dd><em nc_type="eachStoreTotal"></em><?php echo $lang['currency_zh'];?></dd>
              </dl>
            </div></td>
        </tr>
        <?php }?>
      </tbody>
      <tfoot>
        <tr>
          <td colspan="20">
            <style>
              .ncc-all-account{
                font-size: 14px;
              }
            </style>
            <div class="ncc-all-account">商品总价：￥<em id="cartTotal"></em> <span style='padding:0 5px;'>+</span> 税费合计：￥<em id="cartTotal2"></em></div>
            <div class="ncc-all-account">应付款金额（不包含运费）：￥<em id="cartTotal3"></em><?php echo $lang['currency_zh'];?></div>

            <div style='margin-right: 20px;padding-top: 10px;color: gray;font-size: 13px;'>
              在跨境电商平台购买保税商品，每张订单不得超过2千元，每人每年累计消费不得超过2万元。
            </div>


          </td>
        </tr>
      </tfoot>
    </table>
  </form>
  <div class="ncc-bottom"><a id="next_submit"  href="javascript:void(0)" class="ncc-btn ncc-btn-acidblue fr"><i class="icon-pencil"></i><span id='before_submit'>下一步，填写核对购物信息</span></a></div>

  <!-- 猜你喜欢 -->
  <div id="guesslike_div"></div>
</div>

<style>
  /*.layui-layer-title{*/
    /*background: #c8000b;*/
    /*color: #fff;*/
  /*}*/
  /*.layui-layer-btn0{*/
    /*background: #c8000b !important;*/
    /*color: #fff !important;*/
  /*}*/
  /*.layui-layer-btn1{*/
    /*background: #ddd !important;*/
    /*color: #fff !important;*/
  /*}*/
  /*.layui-layer-setwin .layui-layer-close1{*/
    /*border : 0 !important;*/
    /*color: #fff !important;*/
  /*}*/
</style>
<script type="text/javascript">
$(function(){
	//猜你喜欢
	$('#guesslike_div').load('<?php echo urlShop('search', 'get_guesslike', array()); ?>', function(){
        $(this).show();
    });
});


<?php
    $goazhi = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/gaozhishu.txt');
?>

var show_license = false;
$('#before_submit').click(function(){
    var tax = Number($('#cartTotal2').text());
    if(tax != tax){
        tax = 0;
    }

    if(!show_license && tax > 0){
        layer.alert('<?php echo $goazhi;?>',{title : "告知书",btn:"我清楚"}, function () {
            show_license = true;
            $('#before_submit').click();
        });

        return false;
    }


    var split_limit = '<?php echo $config['split_limit']?>';
    var open_tax = '<?php echo $config['open_tax']; ?>';
    var custom_name = '<?php echo $config['custom_interface']?>';
    var order_split = Number('<?php echo $config['order_split']?>');
    var manual_split = Number('<?php echo $config['manual_split']?>');

    <?php
      //如果可以拆，直接在这就存了
      if($config['order_split'] == 1){
          if($config['manual_split'] == 0){
              $_SESSION['want_split'] = 1;
          }
      }
      else{
        unset($_SESSION['want_split']);
      }
    ?>

    //杭州海关不拆分订单
    if(custom_name == 'hangzhou'){
        return true;
    }


    //没有开启行邮税不拆分订单
    if(!Number(open_tax)){
        return true;
    }

    var flag = false;
    //统计各个店铺的税
    $('.shop-list').each(function(){
console.log($(this).find('input:checked').toArray())
      var checkedItem = $(this).find('input:checked').toArray().map(function(item){
          return $(item).closest('tr');
      });


      var tax = 0;
      $(checkedItem).each(function(){
          tax += Number($(this).find('.tax em').text()) * Number($(this).find('.ws0 input[type=text]').val());
      });


      if(tax > split_limit){
        flag = true;
      }

    });
    //如果开启了订单拆分
    if(order_split){
      if(flag){
          //如果开启了提示
          if(manual_split){
            layer.confirm("您的订单已产生行邮税，系统可能会将订单拆分，确认拆分吗？",{title:"温馨提示"},function(index){
                layer.close(index);
                var index = layer.load();
                $.get('/shop/index.php?act=seccode&op=want_split',function(){
                  $('#next_submit').trigger('click');
                });
                return false;
            },function(index){
                layer.close(index);
                $.get('/shop/index.php?act=seccode&op=dont_split',function(){
                  $('#next_submit').trigger('click');
                });
                return false;
            });

          }
          else{
            return true;
          }
      }
      else{
        return true;
      }
    }
    else{
        return true;
    }

    return false;
});

function SetCookie(name,value)
{
var Days = 30; //此 cookie 将被保存 30 天
var exp = new Date();
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}


// function can_split(){

// }


</script>